package com.synnex.mobile.servier.web.content.controller;

import com.synnex.mobile.servier.core.content.bo.ContentBo;
import com.synnex.mobile.servier.core.content.service.ContentService;
import com.synnex.mobile.servier.web.common.controller.AbstractController;
import org.apache.commons.httpclient.util.DateParseException;

import javax.servlet.http.HttpServletRequest;
import java.text.ParseException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author lancec
 */
public abstract class AbstractContentController extends AbstractController {
    protected ContentService contentService;

    public void setContentService(ContentService contentService) {
        this.contentService = contentService;
    }

    public ContentBo getIntroduce(HttpServletRequest request) {
        ContentBo data = contentService.getCompanyIntro();

//        String ftpPath = "http://" + this.getConfig().getFtpHost() + this.getConfig().getFtpDownPath() + "/image/app";
        return data;
    }

    protected ContentBo getContentBo(HttpServletRequest request){
        String type = request.getParameter("type");
        List<ContentBo> contentBos = contentService.getMeetRoundByType(type);
        if(contentBos!=null && !contentBos.isEmpty()){
            return contentBos.get(0);
        }else{
            return new ContentBo();
        }
    }

    protected Map<String,Object> getContentBoListByType(HttpServletRequest request){
        List<ContentBo> contentBoList = contentService.getContentByType(request.getParameter("type"));
        Map<String, Object> model = new HashMap<String, Object>();
        model.put("results", contentBoList);
        model.put("totalCount", contentBoList.size());
        model.put("type",request.getParameter("type"));

        return model;
    }

    protected List<ContentBo> getSessionsByDayAndSection(HttpServletRequest request) throws ParseException {
        String day = request.getParameter("day");
        String section = request.getParameter("section");

        List<ContentBo> sessions = contentService.getSessionByDayAndSection(day,section);
        return sessions;

    }

    protected String getUrl(HttpServletRequest request) {
        String path = request.getServletPath();
        String type = request.getParameter("type");
        return path+"?type="+type;
    }
    protected String getIntroUrl(HttpServletRequest request) {
        String path = request.getServletPath();
        return path+"?type=intro";
    }
    protected String getSessionUrl(HttpServletRequest request) {
        String path = request.getServletPath();
        String day = request.getParameter("day");
        String section = request.getParameter("section");
        return path+"?day="+day+"&section="+section;
    }

}
